<?php

use yii\helpers\Html;
use kartik\grid\GridView;
use yii\helpers\ArrayHelper;
use common\models\user\User;
use yii\helpers\Url;
/* @var $this yii\web\View */
/* @var $searchModel common\models\user\UserSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('app', '验证码管理');
$this->params['breadcrumbs'][] = $this->title;

?>

<?php $this->beginBlock('siderbar'); ?>
<?= $this->render('//layouts/sys-menu') ?>
<?php $this->endBlock(); ?>
<div class="user-index">
<style>
.list-div{
	background-color: #ccc;
	width:100%;
}

.list-div table {
    width: 100%;
	border: 1px solid #ccc;
}
.list-div th {
	background-color: #f5f5f5;
    border-top-left-radius: 3px;
    border-top-right-radius: 3px;
    padding: 10px 15px;
    border-color: #ddd;
    color: #333;
	text-align:center;
    line-height: 20px;
    white-space: nowrap;
}
	
.list-div td {
	border-color:#ccc;
    background: #fff none repeat scroll 0 0;
    line-height: 34px;
    padding: 0 10px;
}
.btn{
	margin-top:5px;
	margin-bottom:5px;
}

</style>

<div class="list-div">
<form method="post" action="<?= yii\helpers\Url::to(['yanzheng/update']);?>" name="theForm" onsubmit="return validate()" >
<table cellpadding='3' cellspacing='1' border='1'>
<tr>
  <th colspan="2">验证码设置</th>
</tr>
<tr>
  <td width="60%" >
  <strong>启用验证码</strong><br />
  图片验证码可以避免恶意批量评论或提交信息，推荐打开验证码功能。注意: 启用验证码会使得部分操作变得繁琐，建议仅在必需时打开<br />
  <img style="vertical-align: middle;cursor: pointer;" id="login_code" src="/yanzheng/captcha/?v="+Math.random() alt="验证码" data-api="captcha" />
  </td>
  <td>
  <input type="checkbox" name="captcha[]" value="1" <?php if(strstr($setting[0]['value'],"1")) echo 'checked="checked"';?>/>新用户注册<br />
  <input type="checkbox" name="captcha[]" value="2" <?php if(strstr($setting[0]['value'],"2")) echo 'checked="checked"';?>/>用户登录<br />
  <input type="checkbox" name="captcha[]" value="4" <?php if(strstr($setting[0]['value'],"4")) echo 'checked="checked"';?>/>找回密码<br />
  <input type="checkbox" name="captcha[]" value="8" <?php if(strstr($setting[0]['value'],"8")) echo 'checked="checked"';?>/>后台管理员登录<br />
  <input type="checkbox" name="captcha[]" value="32" <?php if(strstr($setting[0]['value'],"32")) echo 'checked="checked"';?>/>留言板留言<br />
  </td>
</tr>
<tr>
  <td>
  <strong>验证码类型</strong><br />
  选择“数字”验证码将以数字形式显示，选择“字母”验证码将以字母的形式显示，选择“混合”验证码将以混合的形式显示。注意: 只有在启用了验证码时本设置才有效  </td>
  <td>
   <input type="radio" name="captcha_type" value="numb" <?php if($setting[1]['value']=="numb") echo 'checked="checked"';?>/>数字 <input type="radio" name="captcha_type" value="letter" <?php if($setting[1]['value']=="letter") echo 'checked="checked"';?>/>字母 <input type="radio" name="captcha_type" value="hunhe" <?php if($setting[1]['value']=="hunhe") echo 'checked="checked"';?>/>混合
  </td>
</tr>
<tr>
  <td>
  <strong>验证码图片宽度</strong><br />
  验证码图片的宽度，范围在 40～120 之间  </td>
  <td><input type="text" name="captcha_width" value="<?php if($setting[2]['value']) echo $setting[2]['value']; else echo 80; ?>" /></td>
</tr>
<tr>
  <td>
  <strong>验证码图片高度</strong><br />
  验证码图片的高度，范围在 20～45 之间  </td>
  <td><input type="text" name="captcha_height" value="<?php if($setting[3]['value']) echo $setting[3]['value']; else echo 40; ?>" /></td>
</tr>
<tr>
  <td colspan="2" align="center"><input type="submit" value="保存设置" class="btn btn-primary" /></td>
</tr>
</table>
</form>
</div>
<?= Html::jsFile('@web/js/jquery-2.1.1.min.js') ?>
<script type="text/javascript" language="JavaScript">
<!--

function validate()
{
  var width = document.forms["theForm"].elements["captcha_width"].value;
  var height = document.forms["theForm"].elements["captcha_height"].value;
  if(isNaN(width))
  {
	alert("请输入数字！");
    return false;
  }

  if(parseInt(width) > 120 || parseInt(width) < 40)
  {
	alert("超出了所输范围,请修改！");
    return false;
  }

  if(isNaN(height))
  {
	alert("请输入数字！");
    return false;
  }

  if(parseInt(height) > 45 || parseInt(height) < 20)
  {
	alert("超出了所输范围,请修改！");
    return false;
  }

  return true;
}
//-->

</script>
<script>  
    function refreshCode(obj) {  
        var url = $(obj).attr('data-api');  
  
        if (url) {  
            $.ajax({  
                url: url + '?refresh',  
                dataType: 'json',  
                type: 'get',  
                success: function(data) {  
                    $(obj).attr('src', data.url);  
                }  
            });  
        }  
      }  
  
    $(function () {  
        refreshCode('#login_code');  
  
        $('#login_code').click(function (event) {  
            event.preventDefault();  //阻止默认行为  
            event.stopPropagation(); //该方法将停止事件的传播，阻止它被分派到其他 Document 节点  
  
            refreshCode(this);  
        });  
  
    });  
</script> 
</div>